#ifndef IMAGEPROXY_H_
#define IMAGEPROXY_H_

#include "image.h"

#include <iostream>

using namespace std;

/*
	There are mainly four kinds of proxy:
	virtual, remote, security, smart
 */

class ImageProxy : public Image
{
public:
	ImageProxy()
	{
		m_image = NULL;
	}

	virtual ~ImageProxy()
	{
		if (!m_image)
		{
			delete m_image;
		}
	}

public:
	virtual void show()
	{
		cout<<"ImageProxy::show"<<endl;

		// m_image is initialized and used
		// only when it's needed.
		if (!m_image)
		{
			cout<<"Init m_image here."<<endl;
			m_image = new RealImage();
		}

		m_image->show();
	}

	virtual Extent getExtent()
	{
		cout<<"ImageProxy::getExtent"<<endl;
		if (m_image)
		{
			return m_image->getExtent();
		}
		else
		{
			return m_extent;
		}
	}
	virtual void setExtent(const Extent& extent)
	{
		cout<<"ImageProxy::setExtent"<<endl;
		if (m_image)
		{
			return m_image->setExtent(extent);
		}
		m_extent = extent;
	}

private:
	Image* m_image;
	Extent m_extent;
};

#endif // IMAGEPROXY_H_
